/**
 * Copyright (c) 华南农业大学信息学院蔡超敏2015版权所有
 * 
 * 文件创建时间：2015年4月7日
 */
package org.scauinfo.fpos.service.impl;

import java.io.Serializable;
import java.util.List;

import org.scauinfo.fpos.dao.impl.ProductDao;
import org.scauinfo.fpos.service.ProductService;
import org.scauinfo.fpos.vo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 蔡超敏
 * 
 */
@Service
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductDao productDao;

	@Override
	public void saveProduct(Product product) {
		productDao.save(product);
	}

	@Override
	public void updateProduct(Product product) {
		productDao.update(product);
	}

	@Override
	public void deleteProduct(int id) {
		Product product = productDao.get(id);
		product.setProductType(null);
		productDao.delete(product);
	}

	@Override
	public List<Product> findAllProduct(int page, int rows, String sort,
			String order) {
		return productDao.findAll(page, rows, sort, order);
	}

	@Override
	public int getTotal() {
		return productDao.countAll();
	}

	@Override
	public boolean isExist(String productId) {
		boolean flag = false;
		String hql = "from Product as p where p.productId=" + productId;
		if (productDao.find(hql).size() > 0) {
			flag = true;
		}
		return flag;
	}
	@Override
	public Product get(Serializable id) {
		return productDao.get(id);
	}
	
	public List<Product> getProductsByKeyword(String keyword){
		String hql = "from Product as p where p.productName like '%" + keyword+"%'";
		return productDao.find(hql);
	}
}
